<template>
  <div id="box">
    <!--头部-->
    <header>
      <img src="../../static/img/caidan.png">
      <h3>后台管理系统</h3>
      <ul>
        <li v-for="(item,index) in header" @click="clickFun(index)" :key="index">
          <router-link :to="item.path" :class="item.active?'active':''">{{item.name}}</router-link>
        </li>
      </ul>
    </header>
    <!--分割-->

    <!--路由-->
    <router-view class="router-view">

    </router-view>

    <!--左侧-->
    <div class="left">
      <!--用户显示框-->
      <div class="user">
        欢迎用户:<span @click="dianji">{{this.$store.state.user.userInfo}}</span>
        <i class="el-icon-edit"></i>
      </div>
      <!--展示列表-->
      <div class="zhanshi">
        <el-aside width="auto" style="background-color: rgb(42, 53, 66)">
          <el-menu>
            <el-submenu v-for="(item,index) in side_bar" :key="index" :index="(index+1)+''">
              <template slot="title" class="daohan"><i class="el-icon-message"></i>
                <span @click="dianji" class="daohan_txt">{{item.name}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="1-1" v-for="menu in item.children">
                  <router-link :to="menu.path">{{menu.name}}</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <div class="tuichu">
              <template><i class="el-icon-message"></i>
                <span @click="tuichu">退出系统</span>
              </template>
            </div>
          </el-menu>
        </el-aside>
      </div>
    </div>
  </div>
</template>

<script>
  import store from "../vuex/index"

  export default {
    name: "home",
    beforeMount() {
      //获取侧边栏路由列表
      // console.log(this.$store.state.user.menuInfo[0].header);
      this.side_bar = this.$store.state.user.menuInfo.side_bar;
      console.log(this.side_bar);
      //获取顶部路由列表
      this.header = this.$store.state.user.menuInfo.header;
    },
    store,
    data() {
      return {
        //动态获取用户显示列表
        side_bar: [],
        header: []
      }
    },
    methods: {
      clickFun(id) {
        this.$store.commit('ClickActive', id);
      },
      dianji() {
        // console.log(this.$store.state.user)
        this.$store.commit("ClearActive");
      },
      tuichu() {
        this.$store.commit("loginEdit");
        this.$router.push("/login");
      }
    }
  }
</script>

<style scoped lang="scss">

  .active{
    color: #00d1b2;
  }
  .el-menu-item-group__title {
    padding: 7px 0 0 20px !important;;
  }

  .zhanshi {
    .el-menu-item-group__title { //element-ui 元素
      background-color: red;
    }
  }
  #box{
    overflow: hidden;
  }

  .tuichu {
    padding-left: 25px;
    width: 89%;
    height: 50px;
    line-height: 50px;
    background-color: #2a3542;
    color: #aeb2b7;
    font-size: 15px;
    cursor: pointer;
  }

  .tuichu:hover {
    background-color: #ecf5ff;
    transition: 0.5s all ease;
  }

  .tuichu span {
    margin-left: 13px;
  }

  .router-view {
    position: absolute;
    left: 228px;
    top: 53px;
    background-color: #eee;
  }

  a {
    color: #aeb2b7;
    text-decoration: none;
  }

  header {
    width: 100%;
    /*height: 50px;*/
    background-color: white;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    line-height: 50px;
    border-bottom: 1px solid #eee;
  }

  .left {
    position: fixed;
    width: 15%;
    min-height: 100vh;
    background-color: #2a3542;
    padding-top: 1px;
    /*padding-left: 20px;*/
  }

  header img {
    width: 25px;
    height: 25px;
    vertical-align: middle;
    margin-left: 30px;
  }

  header h3 {
    margin-left: 70px;
    margin-top: -50px;
  }

  header ul li {
    list-style: none;
    float: left;
    margin-left: 30px;
  }

  header ul {
    position: absolute;
    top: 1px;
    left: 210px;
  }

  /*侧边*/
  .user {
    margin-top: 60px;
    color: #aeb2b7;
    font-size: 14px;
    margin-left: 30px;
  }

  .user span {
    cursor: pointer;
  }

  /*路由列表*/
  .left ul {
    margin-top: 30px;
  }

  aside {
    background-color: #2a3542 !important;
  }

  aside ul > li {
    cursor: pointer;
    color: #aeb2b7;
  }

  .el-submenu {
    background-color: #2a3542 !important;
  }

  .el-submenu:hover {
    background-color: #35404d !important;
  }

  .el-submenu__title:hover {
    background-color: #35404d !important;
  }

  .el-submenu__title {
    cursor: pointer;
    color: #aeb2b7;
  }

  el-menu-item {
    background-color: #35404d;
  }

  .daohan_txt {
    color: #aeb2b7;
  }

</style>
